#define _CRT_SECURE_NO_WARNINGS 1

#include <string>

using namespace std;

class Solution {
public:
    int lengthOfLastWord(string s) {
        int length = 0;
        int i = s.size() - 1;
        while (s[i] == ' ')
        {
            --i;
        }
        while (i >= 0 && s[i] != ' ')
        {
            --i;
            ++length;
        }
        return length;
    }
};